#-------------------------------------------------------------------------------
# Name:		OlsApiInitDef
# Purpose:	 From OlsApiInitDef.h
#
# Author:	  SUPER_紫电  QQ:911344755
#
# Created:	 15/08/2022
# Copyright:   (c) SUPER_紫电 2022 All rights reserved.
# Licence:	 <Modified BSD License>
#-------------------------------------------------------------------------------

PHYSICAL_MEMORY_SUPPORT = False

from ctypes import POINTER, WINFUNCTYPE, c_ubyte
from ctypes.wintypes import BOOL, WORD, DWORD, PBYTE, PWORD, PDWORD, HANDLE

BYTE = c_ubyte

DWORD_PTR = POINTER(DWORD)

# DLL
_GetDllStatus = WINFUNCTYPE(None, DWORD)
_GetDllVersion = WINFUNCTYPE(DWORD, PBYTE, PBYTE, PBYTE, PBYTE)
_GetDriverVersion = WINFUNCTYPE(DWORD, PBYTE, PBYTE, PBYTE, PBYTE)
_GetDriverType = WINFUNCTYPE(DWORD)

_InitializeOls = WINFUNCTYPE(BOOL)
_DeinitializeOls = WINFUNCTYPE(None)

# CPU
_IsCpuid = WINFUNCTYPE(BOOL)
_IsMsr = WINFUNCTYPE(BOOL)
_IsTsc = WINFUNCTYPE(BOOL)

_Hlt = WINFUNCTYPE(BOOL)

_Rdmsr = WINFUNCTYPE(DWORD, DWORD , PDWORD , PDWORD)
_Wrmsr = WINFUNCTYPE(DWORD, DWORD , DWORD , DWORD)
_Rdpmc = WINFUNCTYPE(DWORD, DWORD , PDWORD , PDWORD)
_Cpuid = WINFUNCTYPE(DWORD, DWORD , PDWORD , PDWORD, PDWORD, PDWORD)
_Rdtsc = WINFUNCTYPE(DWORD, PDWORD , PDWORD )

_HltTx = WINFUNCTYPE(BOOL, DWORD_PTR)
_RdmsrTx = WINFUNCTYPE(DWORD, DWORD, PDWORD, PDWORD, DWORD_PTR)
_WrmsrTx = WINFUNCTYPE(DWORD, DWORD, DWORD, DWORD, DWORD_PTR)
_RdpmcTx = WINFUNCTYPE(DWORD, DWORD, PDWORD, PDWORD, DWORD_PTR)
_CpuidTx = WINFUNCTYPE(DWORD, DWORD, PDWORD, PDWORD, PDWORD, PDWORD, DWORD_PTR)
_RdtscTx = WINFUNCTYPE(DWORD, PDWORD, PDWORD, DWORD_PTR)

_HltPx = WINFUNCTYPE(BOOL, DWORD_PTR)
_RdmsrPx = WINFUNCTYPE(DWORD, DWORD, PDWORD, PDWORD, DWORD_PTR)
_WrmsrPx = WINFUNCTYPE(DWORD, DWORD, DWORD, DWORD, DWORD_PTR)
_RdpmcPx = WINFUNCTYPE(DWORD, DWORD, PDWORD, PDWORD, DWORD_PTR)
_CpuidPx = WINFUNCTYPE(DWORD, DWORD, PDWORD, PDWORD, PDWORD, PDWORD, DWORD_PTR)
_RdtscPx = WINFUNCTYPE(DWORD, PDWORD, PDWORD, DWORD_PTR)

# I/O
_ReadIoPortByte = WINFUNCTYPE(BYTE, WORD)
_ReadIoPortWord = WINFUNCTYPE(WORD, WORD)
_ReadIoPortDword = WINFUNCTYPE(DWORD, WORD)

_ReadIoPortByteEx = WINFUNCTYPE(BOOL, WORD, PBYTE)
_ReadIoPortWordEx = WINFUNCTYPE(BOOL, WORD, PWORD)
_ReadIoPortDwordEx = WINFUNCTYPE(BOOL, WORD, PDWORD)

_WriteIoPortByte = WINFUNCTYPE(None, WORD, BYTE)
_WriteIoPortWord = WINFUNCTYPE(None, WORD, WORD)
_WriteIoPortDword = WINFUNCTYPE(None, WORD, DWORD)

_WriteIoPortByteEx = WINFUNCTYPE(BOOL, WORD, BYTE)
_WriteIoPortWordEx = WINFUNCTYPE(BOOL, WORD, WORD)
_WriteIoPortDwordEx = WINFUNCTYPE(BOOL, WORD, DWORD)

# PCI
_SetPciMaxBusIndex = WINFUNCTYPE(None, BYTE)

_ReadPciConfigByte = WINFUNCTYPE(BYTE, DWORD, BYTE)
_ReadPciConfigWord = WINFUNCTYPE(WORD, DWORD, BYTE)
_ReadPciConfigDword = WINFUNCTYPE(DWORD, DWORD, BYTE)

_ReadPciConfigByteEx = WINFUNCTYPE(BOOL, DWORD, DWORD, PBYTE)
_ReadPciConfigWordEx = WINFUNCTYPE(BOOL, DWORD, DWORD, PWORD)
_ReadPciConfigDwordEx = WINFUNCTYPE(BOOL, DWORD, DWORD, PDWORD)

_WritePciConfigByte = WINFUNCTYPE(None, DWORD, BYTE, BYTE)
_WritePciConfigWord = WINFUNCTYPE(None, DWORD, BYTE, WORD)
_WritePciConfigDword = WINFUNCTYPE(None, DWORD, BYTE, DWORD)

_WritePciConfigByteEx = WINFUNCTYPE(BOOL, DWORD, DWORD, BYTE)
_WritePciConfigWordEx = WINFUNCTYPE(BOOL, DWORD, DWORD, WORD)
_WritePciConfigDwordEx = WINFUNCTYPE(BOOL, DWORD, DWORD, DWORD)

_FindPciDeviceById = WINFUNCTYPE(DWORD, WORD, WORD, BYTE)
_FindPciDeviceByClass = WINFUNCTYPE(DWORD, BYTE, BYTE, BYTE, BYTE)

# Memory
if PHYSICAL_MEMORY_SUPPORT:
	_ReadDmiMemory = WINFUNCTYPE(DWORD, PBYTE, DWORD, DWORD)
	_ReadPhysicalMemory = WINFUNCTYPE(DWORD, DWORD_PTR, PBYTE, DWORD, DWORD)
	_WritePhysicalMemory = WINFUNCTYPE(DWORD, DWORD_PTR, PBYTE, DWORD, DWORD)
